#include "factory.h"

//利用随机数种子产生salt
int Make_salt(char *str)
{
    int i,flag;
    str[0] = '$';
    str[1] = '6';
    str[2] = '$';
    srand(time(NULL));//通过时间函数设置随机数种子，使得每次运行结果随机。 for(i = 0; i < STR_LEN; i ++)
    for(i = 3; i < 11; i++)
    {
        flag = rand()%3; switch(flag)
        {
        case 0:
            str[i] = rand()%26 + 'a';
            break; 
        case 1:
            str[i] = rand()%26 + 'A';
            break; 
        case 2:
            str[i] = rand()%10 + '0';
            break;
        }
    }
    return 0; 
}

// 得到命令的key值
int cmd_type_func(char *cmd)
{
    if(cmd[0]=='p')
    {
        if(cmd[1]=='u')
            return PUTS;
        else
            return PWD;
    }
    else if(cmd[0]=='g')
        return GETS;
    else if(cmd[0]=='c')
        return CD;
    else if(cmd[0]=='l')
        return LS;
    else if(cmd[0]=='r')
        return REMOVE;
    else if(cmd[0]=='T')
        return TOKEN;
    else 
        return -1;
}